﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class CollectHiddenBirdCommand extends Command {

        public var event:InfoEvent;
        public var userModel:UserModel;
        public var friendsModel:FriendsModel;
        public var sunModel:SunModel;
        public var languageModel:LanguageModel;
        public var missions:MissionModel;

        private static const OFFSET_COIN_ANIMATION:int = 150;

        override public function execute():void{
            var _local1:String;
            if (!this.friendsModel.hiddenBirdCollectedFirstTime){
                _local1 = this.languageModel.getTextByKey("visitfriend_hiddenbird_firsttime");
                this.friendsModel.hiddenBirdCollectedFirstTime = true;
                this.sunModel.simpleMessage = _local1;
            };
            this.friendsModel.removeHiddenBirdFromFriendsObject(this.userModel.visitingFriendID);
            dispatch(new Event(EventConstants.REMOVE_HIDDEN_BIRD_FROM_FRIENDS_MENU));
            this.sendRequest();
        }
        private function sendRequest():void{
            var _local1:Object = {taskType:GameConstants.COLLECT_BIRD, itemType:GameConstants.HIDDEN_BIRD, onResult:this.onSuccess};
            var _local2:Array = [new RequestVO("collect_bird", {id:this.userModel.visitingFriendID})];
            var _local3:TaskRequestEvent = new TaskRequestEvent(EventConstants.SEND_TASK_REQUEST, _local2, _local1);
            dispatch(_local3);
        }
        private function onSuccess(_arg1:ResultVO):void{
            var _local2:Object;
            if (_arg1.success){
                _local2 = _arg1.data.collect_bird;
                this.userModel.numberOfBirdsCollected = _local2.level_info.number_of_birds_collected;
                dispatch(new Event(EventConstants.UPDATE_ACHIEVEMENTS));
                dispatch(new InfoEvent(EventConstants.UPDATE_USER_DATA, null, _local2));
            };
        }

    }
}//package net.wooga.pets.controllers 
